package com.example.mobile2121606109ycg0614homework;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class CarsRVAdapter extends RecyclerView.Adapter<CarsRVAdapter.ViewHolder> {
    private List<Cars> newList;

    public CarsRVAdapter(List<Cars> newList) {
        this.newList = newList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_cars, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Cars car = newList.get(position);
        holder.tvItemID.setText(String.valueOf(car.getId()));
        holder.tvItemStageName.setText(car.getStageName());
        holder.tvItemContent.setText(car.getContent());
    }

    @Override
    public int getItemCount() {
        return newList.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvItemID, tvItemStageName, tvItemContent;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            tvItemID=itemView.findViewById(R.id.tvItemID);
            tvItemStageName=itemView.findViewById(R.id.tvItemStageName);
            tvItemContent=itemView.findViewById(R.id.tvItemContent);
        }
    }
}
